Back to course home
0% completed
Vote For New Content
Google Hard
Shortest Subarray with Sum at Least K (hard)
Solution: Shortest Subarray with Sum at Least K
Reverse Pairs (hard)
Solution: Reverse Pairs
Nth Magical Number (hard)
Solution: Nth Magical Number
Candy (hard)
Solution: Candy
Arithmetic Slices II - Subsequence (hard)
Solution: Arithmetic Slices II - Subsequence
Burst Balloons (hard)
Solution: Burst Balloons
Sum of Distances in Tree (hard)
Solution: Sum of Distances in Tree
Maximum Score of a Good Subarray (hard)
Solution: Maximum Score of a Good Subarray
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Unique Length-3 Palindromic Subsequences (medium)
Problem Statement
Given a string s, return the total number of unique palindromes of length 3 which are subsequences of s. Even if multiple ways exist to obtain the same subsequence, it is still only counted once.
A palindrome string is a sequence of characters that reads the same backward as forward.
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Examples
Example 1:
- Input: s = "abcba"
- Expected Output: 3
- Justification: The three unique length-3 palindromic subsequences are "aba", "aca", and "bcb".
Example 2:
- Input: s = "aba"
- Expected Output: 1
- Justification: The one unique length-3 palindromic subsequence is "aba".
Example 3:
- Input: s = "aacbbcacb"
- Expected Output: 9
- Justification: The nine unique length-3 palindromic subsequences are "aaa", "aca", "aba", "ccc", "cbc", "bbb", "bab", "cac", and "bcb".
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Arithmetic Slices
Solution: Unique Length-3 Palindromic Subsequences
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself